<template>
  <div class="StaffinfoIndex">
    <jxtech-basic-header>
      <template #extra>
        <!-- <jxtech-delete-button @click='StaffinfoIndexState.deletehandler'>
        </jxtech-delete-button> -->
      </template>
    </jxtech-basic-header>

    <el-container>
      <el-aside :width="`${StaffinfoIndexState.asideWidth}px`" class="power-aside">
        <el-input v-model="StaffinfoIndexState.filterText" placeholder="按名称进行搜索" clearable />
        <el-tree class="filter-tree" ref="treeRef" node-key="mrCode" show-checkbox :props="StaffinfoIndexState.defaultProps"
                 :data="StaffinfoIndexState.treeData" :highlight-current="true" :filter-node-method="StaffinfoIndexState.filterNode"
                 @check="StaffinfoIndexState.handleCheckChange" :default-expanded-keys="['MR_00']">
          <template #default="{ node, data }">
            <span class="custom-tree-node">
              <span :title="node.label" class="label">
                <jxtech-svg-icon :icon="'#icon-detail'" :size="16" class="pointer" v-if="data.orgLevel == 1"></jxtech-svg-icon>
                <jxtech-svg-icon :icon="'#icon-attachent'" :size="16" class="pointer" v-else-if="data.orgLevel == 2"></jxtech-svg-icon>
                <jxtech-svg-icon :icon="'#icon-modular'" :size="16" class="pointer" v-else></jxtech-svg-icon>
                {{ node.label }}
              </span>
            </span>
          </template>
        </el-tree>
        <dragResize v-model:asideWidth="StaffinfoIndexState.asideWidth" v-model:dragIng="StaffinfoIndexState.dragIng"></dragResize>
      </el-aside>

      <el-main style="padding: 0;">
        <staffinfo-list-com ref="StaffinfoListComRef" :ParentQueryParam="StaffinfoIndexState.queryParam"></staffinfo-list-com>
      </el-main>
    </el-container>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, reactive, ref, watch, nextTick } from "vue"
import dragResize from "/@/views/base/power-station-power-info/component/drag-resize.vue"
import StaffinfoListCom from "./component/staffinfo-list.vue"
import { getOrgTreeServiceApi } from "/@/api/personnel/bean/staffinfo"
const treeRef = ref()
const StaffinfoListComRef = ref()
const StaffinfoIndexState = reactive({
  asideWidth: 300,
  dragIng: false,
  isStation: false,
  queryParam: { orgCode: [] },
  filterText: "",
  treeData: [],
  defaultProps: {
    children: "mdmOrganizations",
    label: "orgName"
  },
  initTreeData: () => {
    getOrgTreeServiceApi.getOrgTree(null, null).then((response: any) => {
      StaffinfoIndexState.treeData = response.data.aa
    })
  },
  handleCheckChange(nodes: any) {
    // console.log(nodes)
    // console.log(treeRef.value.getCheckedKeys(true))
    StaffinfoIndexState.queryParam.orgCode = treeRef.value
      .getCheckedKeys(true)
      .join(",")
    nextTick(() =>
      StaffinfoListComRef.value.GetStaffInfoListTableRef().loadTable()
    )
  },
  filterNode(value: any, data: any) {
    if (!value) return true
    return data.orgName.indexOf(value) !== -1
  },
  LoadStaffInfoListTable: () => {
    StaffinfoListComRef.value.GetStaffInfoListTableRef().loadTable()
  },
  deletehandler() {
    StaffinfoListComRef.value.exposemultideletehandler()
  }
})
watch(
  () => StaffinfoIndexState.filterText,
  val => {
    treeRef.value!.filter(val)
  }
)
onMounted(() => {
  StaffinfoIndexState.initTreeData()
  StaffinfoIndexState.LoadStaffInfoListTable()
})
</script>

<style lang="scss" scoped>
</style>
